<!-- right-->
<div class="member-main">
    <div>

        <script>
            var prediv = '';
            function showMsg(obj,msgid,url) {
                var currdiv = $('view_msg_pro_'+msgid);

  if(!obj.parentNode.id){
    if(typeof prediv == "object") {prediv.style.display='none'};
    currdiv.style.display = '';
	if($('view_msg_'+msgid))
    //new Request.HTML({url:url,method:'post',update:'view_msg_'+msgid,data:''}).send();
	new Request({
		url:url,
		method:'post',
		data:'',
		onComplete:function(res){
			new Element('div',{'html':res,'style':'*zoom:1'}).inject($('view_msg_'+msgid));
		}
	}).send();

                    obj.parentNode.id = 'span_'+msgid;
                    if(prediv){
                        var link = $('span_'+prediv.id.substr(13)).getElementsByTagName('a')[0];
                        link.className = 'viewmsgoff';
                        toggleBg(link, false);
                    }
                    prediv = $('view_msg_pro_'+msgid);
                    obj.className = 'viewmsg';
                    toggleBg(obj, true);
                    }else{
                    if(currdiv.style.display == 'none'){
                        currdiv.style.display = '';
                        obj.className = 'viewmsg';
                        toggleBg(obj, true);
                        if(prediv) {
                            prediv.style.display = 'none';
                            var link = $('span_'+prediv.id.substr(13)).getElementsByTagName('a')[0];
                            link.className = 'viewmsgoff';
                            toggleBg(link, false);
                        }
                        prediv = currdiv;
                        }else{
                        currdiv.style.display = 'none';
                        obj.className = 'viewmsgoff';
                        toggleBg(obj, false);
                        prediv = '';
                    }
                }
            }

            function toggleBg(el, state){
                while(el.tagName != 'TR'){
                    el = el.parentNode;
                }
                if(!state) $(el).removeClass('msgon');
                else $(el).addClass('msgon');
            }

            function checkAll(obj,box) {
                var tag = obj.getElementsByTagName('input');
                for(var i = 0;i < tag.length;i++){
                    tag[i].checked = box.checked;
                }
            }
        </script>
        <div id="tab-discus" class="section switch">
            <ul class="switchable-triggerBox clearfix">
                <li ><a href="<{link app=b2c ctl='site_member' act='comment'}>"><{t}>我的评论<{/t}></a></li>
                <li><a href="<{link app=b2c ctl='site_member' act='ask'}>"><{t}>我的咨询<{/t}></a></li>
                <li class="active" ><a href="javascript:void(0);"><{t}>站内信<{/t}></a></li>
            </ul>
            <div class="switchable-content">
                <div class="switchable-panel">
                    <!--<textarea class="textarea-lazyload">-->
                        <div id="message-tab" class="switch" style="padding-top:0">
                            <div class="site-mail">
                                <ul class="switchable-triggerBox2 clearfix" >
                                    <li ><a href="<{link app=b2c ctl='site_member' act='send'}>"><{t}>发送消息<{/t}></a></li>
                                    <li class="active"><{t}>收件箱<{/t}><{if $inbox_num}><span>(<{$inbox_num}>)</span><{/if}></li>
                                    <li><a href="<{link app=b2c ctl='site_member' act='track'}>"><{t}>发件箱<{/t}></a><span></span></li>
                                    <li><a href="<{link app=b2c ctl='site_member' act='outbox'}>"><{t}>草稿箱<{/t}></a><{if $outbox_num}><span>(<{$outbox_num}>)</span><{/if}></li>
                  <li style="border:none"><a href="<{link app=b2c ctl='site_member' act='message'}>"><{t}>给管理员发站内信<{/t}></a></li>
                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="title"><{t}>收件箱<{/t}></div>
                    <form action="<{link app=b2c ctl='site_member' full='1' act='del_in_box_msg'}>" method="post" id="form_id">
                        <table width="100%" cellspacing="0" cellpadding="0" class="liststyle-option">
    <col class="span-1 textcenter"></col>
    <col class=" textleft"></col>

                            <tr>
                                <th class="textcenter"><input type="checkbox" onclick="checkAll(this.form,this)" name="chkall" id="chkall" title="<{t}>全选<{/t}>"></th>
                                <td>
                                    <{button type="submit" name="pmsend" label=$___b2c="删除"|t:'b2c' rel="_request"}>
                                </td>
                                <td style="padding-right:10px; text-align:right"><{t}>共有短消息:<{/t}>&nbsp;<em id="pmtotalnum" class="siteparttitle-orage"><{$total_msg}></em></td>
                            </tr>

                        </table>
                        <table width="100%" cellspacing="0" cellpadding="0"  summary="<{t}>收件箱<{/t}>" class="gridlist border-top">
                            <col class="span-1"></col>
                            <col class="span-10"></col>
                            <col class="span-2 "></col>
                            <col class="span-3"></col>
                            <col class="span-3"></col>
                            <col class="span-2"></col>
                            <thead>
                                <tr>
                                    <th class="first">&nbsp;</th>
                                    <th><{t}>标题<{/t}></th>
                                    <th ><{t}>来自<{/t}></th>
                                    <th ><{t}>时间<{/t}></th>
                                    <th ><{t}>操作<{/t}></th>
                                    <th ><{t}>是否阅读<{/t}></th>
                                </tr>
                            </thead>
                            <tbody>
                                <{if count($message)>0}>
                                <{foreach item=msg from=$message}>
                                <tr class="msgon">
                                    <td class="selector textcenter"><input type="checkbox" value=<{$msg.comment_id}> name="delete[]"></td>
                                    <td class="textleft">
                                        <span><a href="<{if $msg.unread}><{else}>javascript:void(0);<{/if}>" onclick="showMsg(this,<{$msg.comment_id}>,'<{link app=b2c ctl='site_member' act='view_msg' arg0=$msg.comment_id }>');return false;" class="viewmsgoff"><{$msg.title|cut:60|nl2br}></a></span></td>
                                    <td align="center"><{$msg.author}></td>
                                    <td align="center"><{$msg.time|cdate:SDATE_STIME}></td>
                                    <td align="center"><div id="hui_<{$msg.comment_id}>" style="display:block" class="hui w50 ma"><a href="javascript:void(0)" <{if $msg.author_id==1}> onclick="Reply('<{link app=b2c ctl=site_member act=ajax_message arg0=$msg.comment_id arg1=reply}>',<{$msg.comment_id}>)";<{else}> onclick="Reply('<{link app=b2c ctl=site_member act=ajax_send arg0=$msg.comment_id arg1=reply}>',<{$msg.comment_id}>)";<{/if}>"  class="btn-a"><span><{t}>回复<{/t}></span></a></div>
                                        <div id="shou_<{$msg.comment_id}>" style="display:none" class="shou w70 ma"><a href="javascript:void(0);" onclick="shou(<{$msg.comment_id}>)" class="btn-a"><span><{t}>收起回复<{/t}></span></a></div>
                                    </td>

                                    <td class="textcenter">
                                        <{if $msg.mem_read_status == 'true'}>
                                        <{t}>已读<{/t}>
                                        <{else}>
                                        <{t}>未读<{/t}>
                                        <{/if}>
                                    </th>
                                </tr>
                                <tr id="view_msg_pro_<{$msg.comment_id}>" style="display:none; white-space:normal;">
                                    <td class="memberviewinfo" colspan="6"><p id="view_msg_<{$msg.comment_id}>" class="pt10 pb10 pl10 pr10"></p></td>
                                </tr>
                                <!----------- -->



                                <tr><td colspan="6"  style="border:none; background:none; overflow:hidden">
                                        <div id="reply_<{$msg.comment_id}>" style="display:none;">
                                        </div>
                                </td></tr>







                                <!----------- -->
                                <{/foreach}>
                                <{else}>
                                <tr>
                                    <td height="60" colspan="6" class="bg-white">
                                        <{t}> 收件箱内没有短信息。<{/t}>
                                    </td>
                                </tr>
                                <{/if}>
                            </tbody>

                        </table>
                        <table width="100%" cellspacing="0" cellpadding="0" class="liststyle-option">
    <col class="span-1 textcenter"></col>
    <col class=" textleft"></col>

                            <tr>
                                <th class="textcenter"><input type="checkbox" onclick="checkAll(this.form,this)" name="chkall" id="chkall" title="<{t}>全选<{/t}>"></th>
                                <td>
                                    <{button type="submit" name="pmsend" label=$___b2c="删除"|t:'b2c' rel="_request"}></td>
                                <td style="padding-right:10px; text-align:right"><{t}>共有短消息:<{/t}>&nbsp;<em id="pmtotalnum" class="siteparttitle-orage"><{$total_msg}></em></td>
                            </tr>

                        </table>
                        <{pagers data=$pager}>
                    </form>


                </div>
            </div>
        </div>

    </div>
    <!-- right-->

    <script>
        function Reply(url,msg_id){
            var allshou = $$('.shou');
            allshou.each(function(cel,k){
                $$('.hui').setStyle('display','block');
                if(cel.id != "shou_"+msg_id) {
                    if( !$(cel).isDisplay() ) return;
                    $(cel).setStyle('display','none');
                    var _t = cel.id.split('_');
                    if( _t[1] )
                    shou(_t[1]);
                    //$('hui_'+msg_id).setStyle('display','inline');
                }
            });

            var alltable = $$('.send_table');
            alltable.each(function(cel,k){
                //if(cel.id != "table_"+msg_id) cel.destroy();
            });
            //new Request.HTML({url:url,method:'post',update:'reply_'+msg_id,data:''}).send();
            new Request({
                url:url,
                method:'post',
                data:'',
                onComplete:function(res){
                    new Element('div',{'html':res}).inject($('reply_'+msg_id));
                }
            }).send();
            $('reply_'+msg_id).setStyle('display','inline');
            $('shou_'+msg_id).setStyle('display','block');
            $('hui_'+msg_id).setStyle('display','none');


        }

        function cha_form(author_id,obj){
            if(author_id){
                $('form_id').action ="<{link app=b2c ctl=site_member act=msgtoadmin}>";
            }
            else{
                $('form_id').action ="<{link app=b2c ctl=site_member act=send_msg}>";
            }
            if(obj.id == 'Submit') $('outbox_btn').value = 'true';
            else $('outbox_btn').value = 'false';

        }

        function shou(msg_id){
            $('shou_'+msg_id).setStyle('display','none');
            $('hui_'+msg_id).setStyle('display','block');
            $('reply_'+msg_id).setStyle('display','none');
            $('table_'+msg_id).destroy();
        }
    </script>
